//
//  AppDelegate+MMGConfig.m
//  MyApp
//
//  Created by Don on 2017/9/6.
//  Copyright © 2017年 com.memego. All rights reserved.
//

#import "AppDelegate+MMGConfig.h"
#import "WXApiManager.h"
#import "MMGConstVenderKeys.h"
#import "SVProgressHUD.h"
#import "UIColor+HexColor.h"
#import "UIImage+CacheViaName.h"

#import <UMSocialCore/UMSocialManager.h>
#import <Bugly/Bugly.h>
#import "UIDevice+MMGUUID.h"

@implementation AppDelegate (MMGConfig)
- (void)mmg_venderConfig {
    
    
    // 向微信注册，用于微信支付
    [WXApi registerApp:kVDSK_Wechat_AppKey withDescription:@"prize_claw"];
    
//    [[UMSocialManager defaultManager] setUmSocialAppkey:kVDSK_UMeng_AppKey];
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:kVDSK_Wechat_AppKey appSecret:kVDSK_Wechat_AppSecret redirectURL:nil];
    
#ifdef DEBUG
    [[UMSocialManager defaultManager] openLog:YES];
#else
    [[UMSocialManager defaultManager] openLog:NO];
#endif
    
    /*! bugly config */
    BuglyConfig * config = [[BuglyConfig alloc] init];
    config.channel = kVDSK_BUGLY_Channel;
    config.blockMonitorEnable = NO;
    config.version = kMMG_SYS_APP_BUILD_VERSION;
    config.reportLogLevel = BuglyLogLevelWarn;
    config.deviceIdentifier = [UIDevice UUID];//TODO: -暂时先这样用
    config.blockMonitorTimeout = 3;
    config.unexpectedTerminatingDetectionEnable = YES;
    
#ifdef DEBUG
    config.debugMode = YES;
    config.channel = @"Dev";
    config.blockMonitorEnable = NO;
    config.reportLogLevel = BuglyLogLevelSilent;
    config.unexpectedTerminatingDetectionEnable = NO;
#else
    config.delegate = self;
#endif
    // 如果接入多个崩溃收藏，bugly官方建议放在其它的之后
    [Bugly startWithAppId:kVDSK_BUGLY_AppId
#if DEBUG
        developmentDevice:YES
#endif
                   config:config];
    
}

- (void)mmg_configSVProgressHUD {
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [SVProgressHUD setMinimumDismissTimeInterval:1.5];
    [SVProgressHUD setSuccessImage:[UIImage mmg_imageNamed:@"happyFace"]];
    [SVProgressHUD setErrorImage:[UIImage mmg_imageNamed:@"sadFace"]];
    [SVProgressHUD setInfoImage:nil];
    [SVProgressHUD setCornerRadius:6];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setFont:[UIFont systemFontOfSize:16]];
    [SVProgressHUD setBackgroundColor:[UIColor mmg_colorWithHex:kMMGColorHex_ToastColor alpha:0.94]];
}

- (BOOL)mmg_handleOpenURL:(NSURL *)url {
    {
        // 顺序不要乱，否则会先被WXApi接受处理
        BOOL umHandleResult = [[UMSocialManager defaultManager] handleOpenURL:url];
        BOOL wxHandleREsult = [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
        return umHandleResult || wxHandleREsult;
    }
}

#pragma mark - BuglyDelegate
//此方法返回的数据，可在bugly平台中异常上报，具体异常信息的跟踪数据附件信息中的crash_attach.log中查看
-(NSString *)attachmentForException:(NSException *)exception{
//    if (CURRENTUSER && !NSStringIsNullOrEmpty(CURRENTUSER.paoId)) {
//        return [NSString stringWithFormat:@"attachmentMessage:\npaoId:%@\ndeviceId:%@",CURRENTUSER.paoId, [UIDevice pw_deviceId]];
//    } else {
//        return [NSString stringWithFormat:@"attachmentMessage:\npaoId:%@\ndeviceId:%@",@"empty", [UIDevice pw_deviceId]];
//    }
    return kMMG_SYS_APP_BUILD_VERSION;
}

@end
